package com.example.redisdemo.demos;

import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

public class IntegerRedisSerializer implements RedisSerializer<Integer> {

    @Override
    public byte[] serialize(Integer integer) throws SerializationException {
        if (integer == null) {
            return new byte[0];
        }
        return integer.toString().getBytes();
    }

    @Override
    public Integer deserialize(byte[] bytes) throws SerializationException {
        if (bytes == null || bytes.length == 0) {
            return null;
        }
        return Integer.parseInt(new String(bytes));
    }
}
